import {
    config
} from '../config.js'

class Http {
    request(param) {
        param.method = param.method || "GET"
        wx.request({
            url: config.base_url + param.url,
            data: param.data,
            method: param.method,
            header: {
                'content-type': 'application/json',
                'appkey': config.appkey
            },
            success: function (res) {
                var code = res.statusCode.toString();
                var startChar = code.charAt(0);
                if (startChar == '2') {
                    param.success && param.success(res.data);
                } else {
                    param.error && param.error(res);
                }
            },
            fail: function () {
                // fail
            }
        })
    }
}
let http = null;

export function creator() {
    if (http == null) {
        http = new Http()
    }
    return http;
}